package com.xiaoxie.web.report;

import com.github.pagehelper.PageInfo;
import com.xiaoxie.common.union.R;
import com.xiaoxie.report.domain.QueryCondition;
import com.xiaoxie.report.domain.ReportConfig;
import com.xiaoxie.report.domain.dto.QueryReportConfigDto;
import com.xiaoxie.report.domain.dto.ReqDto;
import com.xiaoxie.report.domain.vo.ReportConfigVO;
import com.xiaoxie.report.service.ReportConfigService;
import com.xiaoxie.report.service.ReportDataService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import javax.management.Query;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;

@RestController
@RequestMapping("/report")
@Tag(name = "报表管理" ,description = "报表管理")
public class reportController {

    @Resource
    private ReportConfigService reportConfigService;
    @Resource
    private ReportDataService reportDataService;

    @Operation(summary = "分页获取报表配置")
    @GetMapping("/config/list")
    public R getReportConfigList(@RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum, QueryReportConfigDto queryReportConfigDto) {
        PageInfo<ReportConfigVO> pageInfo = reportConfigService.getReportConfigList(pageNum,queryReportConfigDto);
        return R.ok(pageInfo);
    }

    @Operation(summary = "测试获取数据")
    @PostMapping("/data/test")
    public R getData(@RequestBody ReqDto reqDto) {
        System.out.println("reqDto:"+reqDto);
        String sql = reportConfigService.getConfigSqlTemplateByReportId(reqDto.getReportId());
        return R.ok(reportDataService.queryData(sql,reqDto.getParams(), reqDto.getReportId(), reqDto.getPageNum()));
    }
}
